﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ToolwebAQ.database;
using System.Data;
using System.Data.SqlClient;

namespace ToolwebAQ.adminaq
{
    public partial class AQRegisterMember : System.Web.UI.Page
    {
        aquariusDBDataContext db = new aquariusDBDataContext();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_Init(object sender, EventArgs e)
        {
            BindAccount();
        }

        private void BindAccount()
        {
            var listaccount = from acc in db.Tbl_Accounts
                              from role in db.Tbl_roles
                              where acc.coderole == role.coderole
                              group new
                              {
                                  acc,
                                  role
                              } by new
                              {
                                  acc.Accountname,
                                  acc.Email,
                                  acc.Isused,
                                  acc.Idaccount,
                                  acc.Fullname,
                                  role.coderole,
                                  role.Rolename
                              } into gr
                              select new
                              {
                                  coderole = gr.Key.coderole,
                                  Idaccount = gr.Key.Idaccount,
                                  Accountname = gr.Key.Accountname,
                                  Fullname = gr.Key.Fullname,
                                  Email = gr.Key.Email,
                                  Rolename = gr.Key.Rolename,
                                  Isused = gr.Key.Isused
                              };
            SqlCommand cmd = (SqlCommand)db.GetCommand(listaccount);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            gvAccount.DataSource = ds;
            gvAccount.DataBind();
        }
    }

}